package com.tn.wservice.validator;

import java.util.List;

import org.springframework.beans.factory.InitializingBean;

public class AtleastNValidationImpl implements InitializingBean {
	/** */
	private List<String> getterMethods;
	/** */
	private String errorMsg;
	/** */
	private int expectedNotNull;

	public AtleastNValidationImpl() {
		// do nothing
	}

	public void setGetterMethods(List<String> getterMethods) {
		this.getterMethods = getterMethods;
	}

	public List<String> getGetterMethods() {
		return getterMethods;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setExpectedNotNull(int expectedNotNull) {
		this.expectedNotNull = expectedNotNull;
	}

	public int getExpectedNotNull() {
		return expectedNotNull;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		if (null == this.getterMethods && expectedNotNull > 0) {
			throw new Exception(
					"INVALID CONFIGURATION : expectedNotNull cannot be greater than 0 for NULL getterMethods");
		}

		if (this.getterMethods.size() < expectedNotNull) {
			throw new Exception(
					"INVALID CONFIGURATION : expectedNotNull cannot be greater than number of getterMethods.");
		}
	}
}
